#include "glyph.h"
#include "../iimage.h"
#include <assert.h>

ZH_NAMESPACE_BEGIN

namespace FontImpl
{
	Glyph::Glyph(IKFont* pFont)
		: m_pFont(pFont)
		,m_pImage(NULL)
		,m_Code(0)
	{
	}

	Glyph::~Glyph()
	{
	}

	Vec2 Glyph::GetOffset(CharacterDirection direction/* = emDIRECTION_HORIZONTAL*/) const
	{
		if (emDIRECTION_HORIZONTAL == direction)
			return m_HoriOff;
		else
			return m_VertOff;
	}

	void Glyph::SetImage(IImage* body_image)
	{
		m_pImage = body_image;
	}

	void Glyph::SetOffset(const Vec2& hori_offset, const Vec2& vert_offset)
	{
		m_HoriOff = hori_offset;
		m_VertOff = vert_offset;
	}

	void Glyph::Render(const Vec3& pos,
		const ColorRect& color/* = ColorRect(KD_GLYPH_BODY_COLOR)*/,
		const Vec2& scale/* = Vec2(1.0f, 1.0f)*/,
		CharacterDirection direction/* = emDIRECTION_HORIZONTAL*/,
		const Rect* pClip/* = NULL*/
		)
	{
		if (NULL == m_pImage || 0 == m_Size.width || 0 == m_Size.height)
			return;
		
		if (emDIRECTION_HORIZONTAL == direction)
			m_pImage->Render(pos + Vec3(m_HoriOff.x, m_HoriOff.y, 0.0f), color, scale, pClip);
		else
			m_pImage->Render(pos + Vec3(m_VertOff.x, m_VertOff.y, 0.0f), color, scale, pClip);
	}
}	// end of namespace FontImpl
ZH_NAMESPACE_END
